package com.aizhixin.lab.task.service;

import lombok.extern.slf4j.Slf4j;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.aizhixin.lab.common.core.ApiReturnConstants;
import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.common.core.LabReportCore;
import com.aizhixin.lab.common.core.UserInforCore;
import com.aizhixin.lab.common.dto.SortDTO;
import com.aizhixin.lab.common.utils.PageJdbcUtil;
import com.aizhixin.lab.company.domain.AccountDomain;
import com.aizhixin.lab.course.classes.domain.LabReportDomain;
import com.aizhixin.lab.course.classes.entity.LabReport;
import com.aizhixin.lab.task.domain.TaskDomain;
import com.aizhixin.lab.task.entity.Task;
import com.aizhixin.lab.task.entity.TaskFile;
import com.aizhixin.lab.task.repository.TaskFileRepository;
import com.aizhixin.lab.task.repository.TaskRepository;

@Slf4j
@Service
@Transactional
public class TaskFileService {
	@Autowired
	private TaskFileRepository taskFileRepository;
//	@Autowired
//	private PageJdbcUtil pageJdbcUtil;

	
	public void save(TaskFile file) {
		taskFileRepository.save(file);
	}
	public List<TaskFile> findTaskChoiceFile(String taskChoiceId){
		return taskFileRepository.findAllByDeleteFlagAndTaskChoiceId(DataValidity.VALID.getState(),taskChoiceId);
	}
	public void saveList(List<TaskFile> files) {
		taskFileRepository.save(files);

	}
	
	public List<TaskFile> findAllByTaskQuestionId(String questionId) {
		return taskFileRepository.findAllByDeleteFlagAndTaskQuestionId( DataValidity.VALID.getState(),questionId);
	}

	public List<TaskFile> findAllByTaskId(String taskId){
		return taskFileRepository.findAllByDeleteFlagAndTaskIdOrderByOrderNumAsc(DataValidity.VALID.getState(), taskId);
	}

	public void deleteTaskFile(List<TaskFile> files){
		for (TaskFile questionsAccessory : files) {
			questionsAccessory.setDeleteFlag(DataValidity.VALID.getState());
		}
		taskFileRepository.save(files);
	}
}
